package com.fulin.leetcode;

/**
 * TODO
 *
 * @Author fulin
 * @Date 2023/1/30 18:02
 **/
public class Num1669_合并两个链表 {
        public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
                ListNode dump = new ListNode(-1);
                dump.next = list1;
                int index = 0;
                ListNode start = null;
                ListNode end = null;
                while(dump.next != null){
                        if(index == a){
                                start = dump;
                        }
                        if(index == b){
                                end = dump.next.next;
                        }
                        dump = dump.next;
                        index ++;
                }

                start.next = list2;

                ListNode head = list2;
                ListNode end2 = null;
                while(head != null){
                        if(head.next == null){
                                end2 = head;
                        }
                        head = head.next;
                }

                end2.next = end;
                return list1;
        }


}
